package com.kuang.controller;

import com.kuang.pojo.AstUserCardActivate;
import com.kuang.pojo.AstUserCardRecharge;
import com.kuang.service.asset.AstUserCardActivateService;
import com.kuang.service.asset.AstUserCardRechargeService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstUserCardRechargeController {

    @Resource
    AstUserCardRechargeService astUserCardRechargeService;

    /**
     * 获取全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstUserCardRecharges")
    public String getAstUserCardRecharges(Model model){
        List<AstUserCardRecharge> astUserCardRecharges = astUserCardRechargeService.selectAll();
        model.addAttribute("datas",astUserCardRecharges);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_user_card_recharge_list";
    }

    /**
     * 获取数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstUserCardRechargesByExample")
    public String getAstUserCardRechargesByExample(AstUserCardRecharge astUserCardRecharge,Model model){

        List<AstUserCardRecharge> astUserCardRecharges = astUserCardRechargeService.selectAllByExample(astUserCardRecharge);
        model.addAttribute("datas",astUserCardRecharges);
        model.addAttribute("device_code",astUserCardRecharge.getDevice_code());
        model.addAttribute("ver",astUserCardRecharge.getVer());
        return "mqtt/ast_user_card_recharge_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstUserCardRechargesById/{id}")
    public String getAstUserCardRechargesById(@PathVariable("id") String id, Model model){
        AstUserCardRecharge astUserCardRecharge = new AstUserCardRecharge();
        astUserCardRecharge.setAst_user_card_recharge_id(id);
        List<AstUserCardRecharge> astUserCardRecharges = astUserCardRechargeService.selectAllByExample(astUserCardRecharge);
        model.addAttribute("data",astUserCardRecharges.get(0));
        return "mqtt/ast_user_card_recharge_from";
    }

}
